import { useMenuStore } from '@/stores/modules/menu';
import pinia from '@/stores';
import { RouteRecordRaw } from 'vue-router';
import Layout from '@/layout/index.vue';

const store = useMenuStore(pinia);

const modules = import.meta.glob('./modules/*.ts', {
	eager: true
});
export const staticRoutes: RouteRecordRaw[] = [
	{
		path: '/',
		component: Layout,
		redirect: '/home',
		children: [
			{
				path: '/home',
				name: 'Home',
				component: () => import('@/views/home/index.vue'),
				meta: {
					title: '首页',
					icon: 'home',
					affix: true
				}
			}
		]
	},
	{
		path: '/:path(.*)*',
		name: 'notFound',
		component: () => import('@/views/error/404.vue'),
		meta: {
			title: '404',
			hide: true
		}
	},
	{
		path: '/401',
		name: 'noPower',
		component: () => import('@/views/error/401.vue'),
		meta: {
			title: '401',
			hide: true
		}
	}
];
Object.values(modules).forEach((module: any) => {
	if (module.default) {
		staticRoutes.splice(1, 0, module.default);
	}
});

store.addMenu(staticRoutes);
